package com.czy.ekp.datasource;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import javax.sql.DataSource;


public class DynamicDataSource extends AbstractRoutingDataSource {

    @Override
    protected Object determineCurrentLookupKey() {

        return DynamicDataSourceContextHolder.getDataSourceType();

    }

    @Override
    protected DataSource determineTargetDataSource(){

        DataSource db = DynamicDataSourceContextHolder.getDataSource();
        if(db != null){
            return db;
        }

        return super.determineTargetDataSource();
    }


}
